package com.apollographql.apollo;

import com.apollographql.apollo.api.CustomTypeAdapter;
import com.apollographql.apollo.api.Mutation;
import com.apollographql.apollo.api.Operation;
import com.apollographql.apollo.api.Query;
import com.apollographql.apollo.api.ScalarType;
import com.apollographql.apollo.api.ScalarTypeAdapters;
import com.apollographql.apollo.api.Subscription;
import com.apollographql.apollo.api.cache.http.HttpCache;
import com.apollographql.apollo.api.cache.http.HttpCachePolicy;
import com.apollographql.apollo.api.internal.ApolloLogger;
import com.apollographql.apollo.api.internal.Optional;
import com.apollographql.apollo.api.internal.Utils;
import com.apollographql.apollo.cache.CacheHeaders;
import com.apollographql.apollo.cache.normalized.ApolloStore;
import com.apollographql.apollo.cache.normalized.ApolloStoreOperation;
import com.apollographql.apollo.cache.normalized.CacheKeyResolver;
import com.apollographql.apollo.cache.normalized.NormalizedCacheFactory;
import com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter;
import com.apollographql.apollo.cache.normalized.internal.ResponseNormalizer;
import com.apollographql.apollo.fetcher.ApolloResponseFetchers;
import com.apollographql.apollo.fetcher.ResponseFetcher;
import com.apollographql.apollo.interceptor.ApolloInterceptor;
import com.apollographql.apollo.interceptor.ApolloInterceptorFactory;
import com.apollographql.apollo.internal.ApolloCallTracker;
import com.apollographql.apollo.internal.RealApolloCall;
import com.apollographql.apollo.internal.RealApolloPrefetch;
import com.apollographql.apollo.internal.RealApolloStore;
import com.apollographql.apollo.internal.RealApolloSubscriptionCall;
import com.apollographql.apollo.internal.subscription.NoOpSubscriptionManager;
import com.apollographql.apollo.internal.subscription.RealSubscriptionManager;
import com.apollographql.apollo.internal.subscription.SubscriptionManager;
import com.apollographql.apollo.subscription.OnSubscriptionManagerStateChangeListener;
import com.apollographql.apollo.subscription.SubscriptionConnectionParams;
import com.apollographql.apollo.subscription.SubscriptionConnectionParamsProvider;
import com.apollographql.apollo.subscription.SubscriptionManagerState;
import com.apollographql.apollo.subscription.SubscriptionTransport;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.kt.jvm.functions.Function0;
import okhttp3.Call;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Response;

public final class ApolloClient implements ApolloQueryCall.Factory, ApolloMutationCall.Factory, ApolloPrefetch.Factory, ApolloSubscriptionCall.Factory {
    private final ApolloStore apolloStore;
    private final List<ApolloInterceptorFactory> applicationInterceptorFactories;
    private final List<ApolloInterceptor> applicationInterceptors;
    private final ApolloInterceptorFactory autoPersistedOperationsInterceptorFactory;
    private final CacheHeaders defaultCacheHeaders;
    private final HttpCachePolicy.Policy defaultHttpCachePolicy;
    private final ResponseFetcher defaultResponseFetcher;
    private final Executor dispatcher;
    private final boolean enableAutoPersistedQueries;
    private final HttpCache httpCache;
    private final Call.Factory httpCallFactory;
    private final ApolloLogger logger;
    private final ScalarTypeAdapters scalarTypeAdapters;
    private final HttpUrl serverUrl;
    private final SubscriptionManager subscriptionManager;
    private final ApolloCallTracker tracker = new ApolloCallTracker();
    private final boolean useHttpGetMethodForPersistedQueries;
    private final boolean useHttpGetMethodForQueries;
    private final boolean writeToNormalizedCacheAsynchronously;

    public static Builder builder() {
        return new Builder();
    }

    ApolloClient(HttpUrl serverUrl2, Call.Factory httpCallFactory2, HttpCache httpCache2, ApolloStore apolloStore2, ScalarTypeAdapters scalarTypeAdapters2, Executor dispatcher2, HttpCachePolicy.Policy defaultHttpCachePolicy2, ResponseFetcher defaultResponseFetcher2, CacheHeaders defaultCacheHeaders2, ApolloLogger logger2, List<ApolloInterceptor> applicationInterceptors2, List<ApolloInterceptorFactory> applicationInterceptorFactories2, ApolloInterceptorFactory autoPersistedOperationsInterceptorFactory2, boolean enableAutoPersistedQueries2, SubscriptionManager subscriptionManager2, boolean useHttpGetMethodForQueries2, boolean useHttpGetMethodForPersistedQueries2, boolean writeToNormalizedCacheAsynchronously2) {
        this.serverUrl = serverUrl2;
        this.httpCallFactory = httpCallFactory2;
        this.httpCache = httpCache2;
        this.apolloStore = apolloStore2;
        this.scalarTypeAdapters = scalarTypeAdapters2;
        this.dispatcher = dispatcher2;
        this.defaultHttpCachePolicy = defaultHttpCachePolicy2;
        this.defaultResponseFetcher = defaultResponseFetcher2;
        this.defaultCacheHeaders = defaultCacheHeaders2;
        this.logger = logger2;
        if (applicationInterceptorFactories2.isEmpty() || applicationInterceptors2.isEmpty()) {
            this.applicationInterceptors = applicationInterceptors2;
            this.applicationInterceptorFactories = applicationInterceptorFactories2;
            this.autoPersistedOperationsInterceptorFactory = autoPersistedOperationsInterceptorFactory2;
            this.enableAutoPersistedQueries = enableAutoPersistedQueries2;
            this.subscriptionManager = subscriptionManager2;
            this.useHttpGetMethodForQueries = useHttpGetMethodForQueries2;
            this.useHttpGetMethodForPersistedQueries = useHttpGetMethodForPersistedQueries2;
            this.writeToNormalizedCacheAsynchronously = writeToNormalizedCacheAsynchronously2;
            return;
        }
        throw new IllegalArgumentException("You can either use applicationInterceptors or applicationInterceptorFactories but not both at the same time.");
    }

    @Override // com.apollographql.apollo.ApolloMutationCall.Factory
    public <D extends Operation.Data, T, V extends Operation.Variables> ApolloMutationCall<T> mutate(Mutation<D, T, V> mutation) {
        return newCall(mutation).responseFetcher(ApolloResponseFetchers.NETWORK_ONLY);
    }

    @Override // com.apollographql.apollo.ApolloMutationCall.Factory
    public <D extends Operation.Data, T, V extends Operation.Variables> ApolloMutationCall<T> mutate(Mutation<D, T, V> mutation, D withOptimisticUpdates) {
        Utils.checkNotNull(withOptimisticUpdates, "withOptimisticUpdate == null");
        return newCall(mutation).toBuilder().responseFetcher(ApolloResponseFetchers.NETWORK_ONLY).optimisticUpdates(Optional.fromNullable(withOptimisticUpdates)).build();
    }

    @Override // com.apollographql.apollo.ApolloQueryCall.Factory
    public <D extends Operation.Data, T, V extends Operation.Variables> ApolloQueryCall<T> query(Query<D, T, V> query) {
        return newCall(query);
    }

    @Override // com.apollographql.apollo.ApolloPrefetch.Factory
    public <D extends Operation.Data, T, V extends Operation.Variables> ApolloPrefetch prefetch(Operation<D, T, V> operation) {
        return new RealApolloPrefetch(operation, this.serverUrl, this.httpCallFactory, this.scalarTypeAdapters, this.dispatcher, this.logger, this.tracker);
    }

    @Override // com.apollographql.apollo.ApolloSubscriptionCall.Factory
    public <D extends Operation.Data, T, V extends Operation.Variables> ApolloSubscriptionCall<T> subscribe(Subscription<D, T, V> subscription) {
        return new RealApolloSubscriptionCall(subscription, this.subscriptionManager, this.apolloStore, ApolloSubscriptionCall.CachePolicy.NO_CACHE, this.dispatcher, this.logger);
    }

    public void addOnSubscriptionManagerStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener) {
        this.subscriptionManager.addOnStateChangeListener((OnSubscriptionManagerStateChangeListener) Utils.checkNotNull(onStateChangeListener, "onStateChangeListener is null"));
    }

    public void removeOnSubscriptionManagerStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener) {
        this.subscriptionManager.removeOnStateChangeListener((OnSubscriptionManagerStateChangeListener) Utils.checkNotNull(onStateChangeListener, "onStateChangeListener is null"));
    }

    public SubscriptionManagerState getSubscriptionManagerState() {
        return this.subscriptionManager.getState();
    }

    public SubscriptionManager getSubscriptionManager() {
        return this.subscriptionManager;
    }

    public void enableSubscriptions() {
        this.subscriptionManager.start();
    }

    public void disableSubscriptions() {
        this.subscriptionManager.stop();
    }

    @Deprecated
    public CacheHeaders defaultCacheHeaders() {
        return this.defaultCacheHeaders;
    }

    public CacheHeaders getDefaultCacheHeaders() {
        return this.defaultCacheHeaders;
    }

    public void clearHttpCache() {
        HttpCache httpCache2 = this.httpCache;
        if (httpCache2 != null) {
            httpCache2.clear();
        }
    }

    public void clearNormalizedCache(ApolloStoreOperation.Callback<Boolean> callback) {
        Utils.checkNotNull(callback, "callback == null");
        this.apolloStore.clearAll().enqueue(callback);
    }

    public boolean clearNormalizedCache() {
        return this.apolloStore.clearAll().execute().booleanValue();
    }

    @Deprecated
    public ApolloStore apolloStore() {
        return this.apolloStore;
    }

    public ApolloStore getApolloStore() {
        return this.apolloStore;
    }

    public HttpUrl getServerUrl() {
        return this.serverUrl;
    }

    public HttpCache getHttpCache() {
        return this.httpCache;
    }

    public ScalarTypeAdapters getScalarTypeAdapters() {
        return this.scalarTypeAdapters;
    }

    public List<ApolloInterceptor> getApplicationInterceptors() {
        return Collections.unmodifiableList(this.applicationInterceptors);
    }

    public List<ApolloInterceptorFactory> getApplicationInterceptorFactories() {
        return Collections.unmodifiableList(this.applicationInterceptorFactories);
    }

    public ApolloInterceptorFactory getAutoPersistedOperationsInterceptorFactory() {
        return this.autoPersistedOperationsInterceptorFactory;
    }

    public void idleCallback(IdleResourceCallback idleResourceCallback) {
        this.tracker.setIdleResourceCallback(idleResourceCallback);
    }

    public int activeCallsCount() {
        return this.tracker.activeCallsCount();
    }

    public Builder newBuilder() {
        return new Builder();
    }

    /* access modifiers changed from: package-private */
    public Response cachedHttpResponse(String cacheKey) throws IOException {
        HttpCache httpCache2 = this.httpCache;
        if (httpCache2 != null) {
            return httpCache2.read(cacheKey);
        }
        return null;
    }

    private <D extends Operation.Data, T, V extends Operation.Variables> RealApolloCall<T> newCall(Operation<D, T, V> operation) {
        return (RealApolloCall<T>) RealApolloCall.builder().operation(operation).serverUrl(this.serverUrl).httpCallFactory(this.httpCallFactory).httpCache(this.httpCache).httpCachePolicy(this.defaultHttpCachePolicy).scalarTypeAdapters(this.scalarTypeAdapters).apolloStore(this.apolloStore).responseFetcher(this.defaultResponseFetcher).cacheHeaders(this.defaultCacheHeaders).dispatcher(this.dispatcher).logger(this.logger).applicationInterceptors(this.applicationInterceptors).applicationInterceptorFactories(this.applicationInterceptorFactories).autoPersistedOperationsInterceptorFactory(this.autoPersistedOperationsInterceptorFactory).tracker(this.tracker).refetchQueries(Collections.emptyList()).refetchQueryNames(Collections.emptyList()).enableAutoPersistedQueries(this.enableAutoPersistedQueries).useHttpGetMethodForQueries(this.useHttpGetMethodForQueries).useHttpGetMethodForPersistedQueries(this.useHttpGetMethodForPersistedQueries).writeToNormalizedCacheAsynchronously(this.writeToNormalizedCacheAsynchronously).build();
    }

    public static class Builder {
        ApolloStore apolloStore;
        final List<ApolloInterceptorFactory> applicationInterceptorFactories;
        final List<ApolloInterceptor> applicationInterceptors;
        ApolloInterceptorFactory autoPersistedOperationsInterceptorFactory;
        Optional<NormalizedCacheFactory> cacheFactory;
        Optional<CacheKeyResolver> cacheKeyResolver;
        Call.Factory callFactory;
        final Map<ScalarType, CustomTypeAdapter<?>> customTypeAdapters;
        CacheHeaders defaultCacheHeaders;
        HttpCachePolicy.Policy defaultHttpCachePolicy;
        ResponseFetcher defaultResponseFetcher;
        Executor dispatcher;
        boolean enableAutoPersistedQueries;
        boolean enableAutoPersistedSubscriptions;
        HttpCache httpCache;
        Logger logger;
        HttpUrl serverUrl;
        SubscriptionConnectionParamsProvider subscriptionConnectionParams;
        long subscriptionHeartbeatTimeout;
        SubscriptionManager subscriptionManager;
        Optional<SubscriptionTransport.Factory> subscriptionTransportFactory;
        boolean useHttpGetMethodForPersistedQueries;
        boolean useHttpGetMethodForQueries;
        boolean writeToNormalizedCacheAsynchronously;

        Builder() {
            this.apolloStore = ApolloStore.NO_APOLLO_STORE;
            this.cacheFactory = Optional.absent();
            this.cacheKeyResolver = Optional.absent();
            this.defaultHttpCachePolicy = HttpCachePolicy.NETWORK_ONLY;
            this.defaultResponseFetcher = ApolloResponseFetchers.CACHE_FIRST;
            this.defaultCacheHeaders = CacheHeaders.NONE;
            this.customTypeAdapters = new LinkedHashMap();
            this.logger = null;
            this.applicationInterceptors = new ArrayList();
            this.applicationInterceptorFactories = new ArrayList();
            this.autoPersistedOperationsInterceptorFactory = null;
            this.subscriptionManager = new NoOpSubscriptionManager();
            this.subscriptionTransportFactory = Optional.absent();
            this.subscriptionConnectionParams = new SubscriptionConnectionParamsProvider.Const(new SubscriptionConnectionParams());
            this.subscriptionHeartbeatTimeout = -1;
        }

        private Builder(ApolloClient apolloClient) {
            this.apolloStore = ApolloStore.NO_APOLLO_STORE;
            this.cacheFactory = Optional.absent();
            this.cacheKeyResolver = Optional.absent();
            this.defaultHttpCachePolicy = HttpCachePolicy.NETWORK_ONLY;
            this.defaultResponseFetcher = ApolloResponseFetchers.CACHE_FIRST;
            this.defaultCacheHeaders = CacheHeaders.NONE;
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            this.customTypeAdapters = linkedHashMap;
            this.logger = null;
            ArrayList arrayList = new ArrayList();
            this.applicationInterceptors = arrayList;
            ArrayList arrayList2 = new ArrayList();
            this.applicationInterceptorFactories = arrayList2;
            this.autoPersistedOperationsInterceptorFactory = null;
            this.subscriptionManager = new NoOpSubscriptionManager();
            this.subscriptionTransportFactory = Optional.absent();
            this.subscriptionConnectionParams = new SubscriptionConnectionParamsProvider.Const(new SubscriptionConnectionParams());
            this.subscriptionHeartbeatTimeout = -1;
            this.callFactory = apolloClient.httpCallFactory;
            this.serverUrl = apolloClient.serverUrl;
            this.httpCache = apolloClient.httpCache;
            this.apolloStore = apolloClient.apolloStore;
            this.defaultHttpCachePolicy = apolloClient.defaultHttpCachePolicy;
            this.defaultResponseFetcher = apolloClient.defaultResponseFetcher;
            this.defaultCacheHeaders = apolloClient.defaultCacheHeaders;
            linkedHashMap.putAll(apolloClient.scalarTypeAdapters.getCustomAdapters());
            this.dispatcher = apolloClient.dispatcher;
            this.logger = apolloClient.logger.getLogger();
            arrayList.addAll(apolloClient.applicationInterceptors);
            arrayList2.addAll(apolloClient.applicationInterceptorFactories);
            this.autoPersistedOperationsInterceptorFactory = apolloClient.getAutoPersistedOperationsInterceptorFactory();
            this.enableAutoPersistedQueries = apolloClient.enableAutoPersistedQueries;
            this.subscriptionManager = apolloClient.subscriptionManager;
            this.useHttpGetMethodForQueries = apolloClient.useHttpGetMethodForQueries;
            this.useHttpGetMethodForPersistedQueries = apolloClient.useHttpGetMethodForPersistedQueries;
            this.writeToNormalizedCacheAsynchronously = apolloClient.writeToNormalizedCacheAsynchronously;
        }

        public Builder okHttpClient(OkHttpClient okHttpClient) {
            return callFactory((Call.Factory) Utils.checkNotNull(okHttpClient, "okHttpClient is null"));
        }

        public Builder callFactory(Call.Factory factory) {
            this.callFactory = (Call.Factory) Utils.checkNotNull(factory, "factory == null");
            return this;
        }

        public Builder serverUrl(HttpUrl serverUrl2) {
            this.serverUrl = (HttpUrl) Utils.checkNotNull(serverUrl2, "serverUrl is null");
            return this;
        }

        public Builder serverUrl(String serverUrl2) {
            this.serverUrl = HttpUrl.parse((String) Utils.checkNotNull(serverUrl2, "serverUrl == null"));
            return this;
        }

        public Builder httpCache(HttpCache httpCache2) {
            this.httpCache = (HttpCache) Utils.checkNotNull(httpCache2, "httpCache == null");
            return this;
        }

        public Builder normalizedCache(NormalizedCacheFactory normalizedCacheFactory) {
            return normalizedCache(normalizedCacheFactory, CacheKeyResolver.DEFAULT);
        }

        public Builder normalizedCache(NormalizedCacheFactory normalizedCacheFactory, CacheKeyResolver keyResolver) {
            return normalizedCache(normalizedCacheFactory, keyResolver, false);
        }

        public Builder normalizedCache(NormalizedCacheFactory normalizedCacheFactory, CacheKeyResolver keyResolver, boolean writeToCacheAsynchronously) {
            this.cacheFactory = Optional.fromNullable(Utils.checkNotNull(normalizedCacheFactory, "normalizedCacheFactory == null"));
            this.cacheKeyResolver = Optional.fromNullable(Utils.checkNotNull(keyResolver, "cacheKeyResolver == null"));
            this.writeToNormalizedCacheAsynchronously = writeToCacheAsynchronously;
            return this;
        }

        public <T> Builder addCustomTypeAdapter(ScalarType scalarType, CustomTypeAdapter<T> customTypeAdapter) {
            this.customTypeAdapters.put(scalarType, customTypeAdapter);
            return this;
        }

        public Builder dispatcher(Executor dispatcher2) {
            this.dispatcher = (Executor) Utils.checkNotNull(dispatcher2, "dispatcher == null");
            return this;
        }

        public Builder defaultHttpCachePolicy(HttpCachePolicy.Policy cachePolicy) {
            this.defaultHttpCachePolicy = (HttpCachePolicy.Policy) Utils.checkNotNull(cachePolicy, "cachePolicy == null");
            return this;
        }

        public Builder defaultCacheHeaders(CacheHeaders cacheHeaders) {
            this.defaultCacheHeaders = (CacheHeaders) Utils.checkNotNull(cacheHeaders, "cacheHeaders == null");
            return this;
        }

        public Builder defaultResponseFetcher(ResponseFetcher defaultResponseFetcher2) {
            this.defaultResponseFetcher = (ResponseFetcher) Utils.checkNotNull(defaultResponseFetcher2, "defaultResponseFetcher == null");
            return this;
        }

        public Builder logger(Logger logger2) {
            this.logger = logger2;
            return this;
        }

        public Builder addApplicationInterceptor(ApolloInterceptor interceptor) {
            this.applicationInterceptors.add(interceptor);
            return this;
        }

        public Builder addApplicationInterceptorFactory(ApolloInterceptorFactory interceptorFactory) {
            this.applicationInterceptorFactories.add(interceptorFactory);
            return this;
        }

        public Builder setAutoPersistedOperationsInterceptorFactory(ApolloInterceptorFactory interceptorFactory) {
            this.autoPersistedOperationsInterceptorFactory = interceptorFactory;
            return this;
        }

        public Builder enableAutoPersistedQueries(boolean enableAutoPersistedQueries2) {
            this.enableAutoPersistedQueries = enableAutoPersistedQueries2;
            return this;
        }

        public Builder subscriptionTransportFactory(SubscriptionTransport.Factory subscriptionTransportFactory2) {
            this.subscriptionTransportFactory = Optional.of(Utils.checkNotNull(subscriptionTransportFactory2, "subscriptionTransportFactory is null"));
            return this;
        }

        public Builder subscriptionConnectionParams(SubscriptionConnectionParams connectionParams) {
            this.subscriptionConnectionParams = new SubscriptionConnectionParamsProvider.Const((SubscriptionConnectionParams) Utils.checkNotNull(connectionParams, "connectionParams is null"));
            return this;
        }

        public Builder subscriptionConnectionParams(SubscriptionConnectionParamsProvider provider) {
            this.subscriptionConnectionParams = (SubscriptionConnectionParamsProvider) Utils.checkNotNull(provider, "provider is null");
            return this;
        }

        public Builder subscriptionHeartbeatTimeout(long timeout, TimeUnit timeUnit) {
            Utils.checkNotNull(timeUnit, "timeUnit is null");
            this.subscriptionHeartbeatTimeout = Math.max(timeUnit.toMillis(timeout), TimeUnit.SECONDS.toMillis(10));
            return this;
        }

        public Builder enableAutoPersistedSubscriptions(boolean enableAutoPersistedSubscriptions2) {
            this.enableAutoPersistedSubscriptions = enableAutoPersistedSubscriptions2;
            return this;
        }

        public Builder useHttpGetMethodForQueries(boolean useHttpGetMethodForQueries2) {
            this.useHttpGetMethodForQueries = useHttpGetMethodForQueries2;
            return this;
        }

        public Builder useHttpGetMethodForPersistedQueries(boolean useHttpGetMethodForPersistedQueries2) {
            this.useHttpGetMethodForPersistedQueries = useHttpGetMethodForPersistedQueries2;
            return this;
        }

        public ApolloClient build() {
            Executor dispatcher2;
            final ApolloStore apolloStore2;
            Utils.checkNotNull(this.serverUrl, "serverUrl is null");
            ApolloLogger apolloLogger = new ApolloLogger(this.logger);
            Call.Factory callFactory2 = this.callFactory;
            if (callFactory2 == null) {
                callFactory2 = new OkHttpClient();
            }
            HttpCache httpCache2 = this.httpCache;
            if (httpCache2 != null) {
                callFactory2 = addHttpCacheInterceptorIfNeeded(callFactory2, httpCache2.interceptor());
            }
            Executor dispatcher3 = this.dispatcher;
            if (dispatcher3 == null) {
                dispatcher2 = defaultDispatcher();
            } else {
                dispatcher2 = dispatcher3;
            }
            ScalarTypeAdapters scalarTypeAdapters = new ScalarTypeAdapters(Collections.unmodifiableMap(this.customTypeAdapters));
            ApolloStore apolloStore3 = this.apolloStore;
            Optional<NormalizedCacheFactory> cacheFactory2 = this.cacheFactory;
            Optional<CacheKeyResolver> cacheKeyResolver2 = this.cacheKeyResolver;
            if (!cacheFactory2.isPresent() || !cacheKeyResolver2.isPresent()) {
                apolloStore2 = apolloStore3;
            } else {
                apolloStore2 = new RealApolloStore(cacheFactory2.get().createChain(RecordFieldJsonAdapter.create()), cacheKeyResolver2.get(), scalarTypeAdapters, dispatcher2, apolloLogger);
            }
            SubscriptionManager subscriptionManager2 = this.subscriptionManager;
            Optional<SubscriptionTransport.Factory> subscriptionTransportFactory2 = this.subscriptionTransportFactory;
            if (subscriptionTransportFactory2.isPresent()) {
                subscriptionManager2 = new RealSubscriptionManager(scalarTypeAdapters, subscriptionTransportFactory2.get(), this.subscriptionConnectionParams, dispatcher2, this.subscriptionHeartbeatTimeout, new Function0<ResponseNormalizer<Map<String, Object>>>() {
                    /* class com.apollographql.apollo.ApolloClient.Builder.AnonymousClass1 */

                    @Override // com.kt.jvm.functions.Function0
                    public ResponseNormalizer<Map<String, Object>> invoke() {
                        return apolloStore2.networkResponseNormalizer();
                    }
                }, this.enableAutoPersistedSubscriptions);
            }
            return new ApolloClient(this.serverUrl, callFactory2, httpCache2, apolloStore2, scalarTypeAdapters, dispatcher2, this.defaultHttpCachePolicy, this.defaultResponseFetcher, this.defaultCacheHeaders, apolloLogger, Collections.unmodifiableList(this.applicationInterceptors), Collections.unmodifiableList(this.applicationInterceptorFactories), this.autoPersistedOperationsInterceptorFactory, this.enableAutoPersistedQueries, subscriptionManager2, this.useHttpGetMethodForQueries, this.useHttpGetMethodForPersistedQueries, this.writeToNormalizedCacheAsynchronously);
        }

        private Executor defaultDispatcher() {
            return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactory() {
                /* class com.apollographql.apollo.ApolloClient.Builder.AnonymousClass2 */

                public Thread newThread(Runnable runnable) {
                    return new Thread(runnable, "Apollo Dispatcher");
                }
            });
        }

        private static Call.Factory addHttpCacheInterceptorIfNeeded(Call.Factory callFactory2, Interceptor httpCacheInterceptor) {
            if (!(callFactory2 instanceof OkHttpClient)) {
                return callFactory2;
            }
            OkHttpClient client = (OkHttpClient) callFactory2;
            for (Interceptor interceptor : client.interceptors()) {
                if (interceptor.getClass().equals(httpCacheInterceptor.getClass())) {
                    return callFactory2;
                }
            }
            return client.newBuilder().addInterceptor(httpCacheInterceptor).build();
        }
    }
}
